package com.yan;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//extends继承HttpServlet  就实现了Servlet的接口
public class Heeloserlvet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       // super.doGet(req, resp);
        //1.获取前段的参数
        String method = req.getParameter("method");
        if (method.equals("add")) {
            req.getSession().setAttribute("msg","执行的是add");
        }
        if (method.equals("delete")) {
            req.getSession().setAttribute("msg","=========delete");
        }
        //2.调用业务逻辑
        //3.视图跳转或者重定向

        //转发
        req.getRequestDispatcher("/WEB-INF/jsp/test.jsp").forward(req,resp);
       // resp.sendRedirect();  重定向
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      //  super.doPost(req, resp);

        doGet(req, resp);
    }
}
